package com.haixiaoke.saas.enterprise.order.controller;

import com.haixiaoke.saas.common.annotation.Log;
import com.haixiaoke.saas.common.annotation.RepeatSubmit;
import com.haixiaoke.saas.common.annotation.TenantScope;
import com.haixiaoke.saas.common.core.domain.AjaxResult;
import com.haixiaoke.saas.common.core.page.TableDataInfo;
import com.haixiaoke.saas.common.enums.BusinessType;
import com.haixiaoke.saas.common.utils.poi.ExcelUtil;
import com.haixiaoke.saas.order.domain.OrderLessee;
import com.haixiaoke.saas.order.service.IOrderLesseeService;
import com.haixiaoke.saas.system.BaseController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 订单承租者信息Controller
 *
 * @author qixi
 * @date 2024-04-03
 */
@RestController
@RequestMapping("/enterprise/order/orderLessee")
public class EnterpriseOrderLesseeController extends BaseController {
    @Autowired
    private IOrderLesseeService orderLesseeService;

    /**
     * 查询订单承租者信息列表
     */
    @PreAuthorize("@ss.hasPermi('order:orderLessee:list')")
    @GetMapping("/list")
    public TableDataInfo list(OrderLessee orderLessee) {
        startPage();
        List<OrderLessee> list = orderLesseeService.selectOrderLesseeList(orderLessee);
        return getDataTable(list);
    }

    /**
     * 导出订单承租者信息列表
     */
    @PreAuthorize("@ss.hasPermi('order:orderLessee:export')")
    @Log(title = "订单承租者信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, OrderLessee orderLessee) {
        List<OrderLessee> list = orderLesseeService.selectOrderLesseeList(orderLessee);
        ExcelUtil<OrderLessee> util = new ExcelUtil<OrderLessee>(OrderLessee.class);
        util.exportExcel(response, list, "订单承租者信息数据");
    }

    /**
     * 获取订单承租者信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('order:orderLessee:query')")
    @GetMapping(value = "/{lesseeId}")
    public AjaxResult getInfo(@PathVariable("lesseeId") Long lesseeId) {
        return success(orderLesseeService.selectOrderLesseeByLesseeId(lesseeId));
    }

    /**
     * 新增订单承租者信息
     */
    @PreAuthorize("@ss.hasPermi('order:orderLessee:add')")
    @Log(title = "订单承租者信息", businessType = BusinessType.INSERT)
    @PostMapping
    @RepeatSubmit
    public AjaxResult add(@RequestBody OrderLessee orderLessee) {
        return toAjax(orderLesseeService.insertOrderLessee(orderLessee));
    }


    /**
     * 新增承租者信息
     */
    @PostMapping("/addOrderLessee")
    @RepeatSubmit
    public AjaxResult addOrderLessee(@RequestBody OrderLessee orderLessee) {
        return toAjax(orderLesseeService.addOrderLessee(orderLessee));
    }

    /**
     * 修改订单承租者信息
     */
    @PreAuthorize("@ss.hasPermi('order:orderLessee:edit')")
    @Log(title = "订单承租者信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody OrderLessee orderLessee) {
        return toAjax(orderLesseeService.updateOrderLessee(orderLessee));
    }

    /**
     * 删除订单承租者信息
     */
    @PreAuthorize("@ss.hasPermi('order:orderLessee:remove')")
    @Log(title = "订单承租者信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{lesseeIds}")
    public AjaxResult remove(@PathVariable Long[] lesseeIds) {
        return toAjax(orderLesseeService.deleteOrderLesseeByLesseeIds(lesseeIds));
    }
}
